import http, {adornData, adornParams, buildUrl} from "@/util/request.ts";

interface MedicineData {
    id: string
    code: string
    endcode: string
    name: string
    spec: string
    unit: string
    prescribeUnit: string
    nactionInsurCode: string
    qty: number
    price: number
}

interface MedicineSearchData {
    code: string
    endcode: string
    name: string
    spec: string
    unit: string
    prescribeUnit: string
    nactionInsurCode: string
}

const MedicineAPI = {
    findPage(Search: Partial<MedicineSearchData>, current: number = 1, size: number = 20) {
        const data = {
            ...Search,
            current,
            size
        }
        return http<any, PageResult<MedicineData[]>>({
            url: buildUrl('/api/medicine/list'),
            method: 'get',
            params: adornParams(data)
        })
    },
    submit(data: MedicineData) {
        return http({
            url: buildUrl('/api/medicine/data'),
            method: data.id ? 'put' : 'post',
            data: adornData(data)
        })
    },
    delete(id: string) {
        return http({
            url: buildUrl(`/api/medicine/data/${id}`),
            method: 'delete'
        })
    },
    findSelectList(params: Record<string, any>) {
        return http<any, PageResult<MedicineData[]>>({
            url: buildUrl('/api/medicine/find/select/list'),
            method: 'get',
            params: adornParams(params)
        })
    }
}

export type {MedicineData, MedicineSearchData}
export default MedicineAPI
